home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
051-060
/
amok58
/
sortedlists
/
sortedlists.mod
< prev
next >
Wrap
Text File
|
1993-11-04
|
3KB
|
102 lines
(* ==================================================================== *)
(* === SortedLists ==================================================== *)
(* ==================================================================== *)
(*
:Program. SortedLists.MOD
:Contents. simple extension of Lists.MOD to allow sorted lists
:Author. Peter Fröhlich [phf]
:Copyright. Public Domain
:Language. Oberon (revised)
:Translator. Amiga Oberon V2.01
:History. V0.1 [phf] 19-Aug-1991 [created]
:History. V0.1 [phf] 30-Aug-1991 [last edit]
:Support. -
:Imports. -
:Bugs. none known, but implementation is quit inefficient
:Address. Z-NET:P.FROEHLICH@NEXT-BOX.ZER
:Remark. This is a quick hack! Feel free to improve on
:Remark. my code, but post any changes to the net, please.
*)
(* ==================================================================== *)
MODULE SortedLists;
(* ==================================================================== *)
(* === Imports ======================================================== *)
(* ==================================================================== *)
IMPORT
li : Lists;
(* ==================================================================== *)
(* === Types ========================================================== *)
(* ==================================================================== *)
TYPE
CompProc * = PROCEDURE(a,b: li.NodePtr): INTEGER;
(*
CompProc is used to compare two nodes. Its result should be:
< 0, if a < b
> 0, if a > b
or
= 0, if both nodes are equal
*)
(* ==================================================================== *)
(* === Procedures ===================================================== *)
(* ==================================================================== *)
(* --- AddSorted ------------------------------------------------------ *)
(*
:Semantic. inserts a node at the proper location in a list
:Note. quit inefficient but i see no other solutions
*)
PROCEDURE AddSorted*(VAR list: li.List; n: li.NodePtr; comp: CompProc);
VAR
h : li.NodePtr;
ok : BOOLEAN;
BEGIN
ok := FALSE;
IF li.Empty(list) THEN
li.AddHead(list,n);
ELSE
h := li.Head(list);
WHILE (h # NIL) DO
IF comp(h,n) >= 0 THEN
li.AddBefore(list,n,h); ok := TRUE;
END;
li.Succ(h);
END;
IF NOT ok THEN
li.AddTail(list,n);
END;
END;
END AddSorted;
(* -------------------------------------------------------------------- *)
(* --- Sort (not implemented) ----------------------------------------- *)
(*
:Semantic. (re-)sort a list
*)
PROCEDURE Sort(VAR list: li.List; comp: CompProc);
BEGIN
IF NOT (li.Empty(list)) THEN
(* modify QuickSort ? *)
END;
END Sort;
(* -------------------------------------------------------------------- *)
(* ==================================================================== *)
(* ==================================================================== *)
(* === Main =========================================================== *)
(* ==================================================================== *)
BEGIN (* SortedLists *)
END SortedLists.
(* ==================================================================== *)